"use strict";
const {
  MYSQL_DB,
  MYSQL_PWD,
  MYSQL_USER,
  MYSQL_PORT,
  MYSQL_HOST,
  REDIS_PORT,
  REDIS_HOST,
  REDIS_PWD,
} = require("./db");

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = (appInfo) => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = (exports = {});

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + "_1633795757548_3299";

  // add your middleware config here
  config.middleware = [];

  // add WebSocket Server config
  config.io = {
    namespace: {
      "/": {
        connectionMiddleware: ["auth"],
        packetMiddleware: ["filter"], // 客户端向服务端发起请求时执行的拦截器
      },
    },
  };

  // redis插件配置
  config.redis = {
    client: {
      port: REDIS_PORT,
      host: REDIS_HOST,
      password: REDIS_PWD,
      db: 0,
    },
  };

  config.mysql = {
    client: {
      host: MYSQL_HOST,
      port: MYSQL_PORT,
      user: MYSQL_USER,
      password: MYSQL_PWD,
      database: MYSQL_DB,
    },
    app: true, // 把MySQL对象挂载到APP对象上
    agent: false, // 是否加载代理，false是不加
  };

  config.jwt = {
    enable: true,
    secret: process.env.JWT_SECRET || "",
    ignore: ["/user/login", "/user/createUser"],
  };

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
    jwtExpires: "30d",
  };

  return {
    ...config,
    ...userConfig,
  };
};
